<template>
  <div>
    <el-container>
      <el-main>
        <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal"   active-text-color="#545c64" @select="handleSelect">
          <el-menu-item index="1"><span style="font-weight: bold;font-size: large">教学班</span></el-menu-item>
          <el-menu-item index="2"><span style="font-weight: bold;font-size: large">行政班</span></el-menu-item>
          <el-button v-if="showFirstButton" type="primary"  class="button" @click="dialogFormVisible = true"   style="margin-top: 10px;margin-left: 20px">教学班预设</el-button>
          <el-button v-if="showSecondButton"  type="primary" class="button" @click="dialogFormVisible_administrativeClass = true" style="margin-top: 10px;margin-left: 20px">行政班创建</el-button>
        </el-menu>
        <el-card class="box-card" style="margin-top: 10px">
          <div>
            <el-table
              v-if="chooseOne"
              :data="tableData"
              style="width: 100%"
              size="small"
              stripe
            >
              <el-table-column prop="className" label="班级名称" >
                <template slot-scope="scope">
                  {{ scope.row.className ? scope.row.className :'暂无' }}
                </template>
              </el-table-column>
              <el-table-column prop="limitOfNumber" label="人数" width="120px">
                <template slot-scope="scope">
                  {{ scope.row.limitOfNumber ? scope.row.currentNumber?scope.row.currentNumber+'/'+scope.row.limitOfNumber:'0/'+scope.row.limitOfNumber :'暂无数据' }}
                </template>
              </el-table-column>
              <el-table-column prop="classState" label="报名状态"  align="center">
                <template slot-scope="scope">
                  <el-tag
                    :type="scope.row.classState === 0 ? 'info' : scope.row.classState=== 1 ? '':scope.row.classState === 2 ?'danger':''"
                  >
                    {{ scope.row.classState===0 ? '未开启报名' :scope.row.classState===1 ?'报名进行':scope.row.classState===2 ?'报名截止':'暂无' }}
                  </el-tag>
                </template>
              </el-table-column>
              <el-table-column label="报名开启"  align="center">
                <!--                <template slot-scope="scope">-->
                <!--                  <el-button size="small" type="warning" :disabled="ifDisabled[scope.$index]" @click="changeStatus(scope.$index)">开启</el-button>-->
                <!--                </template>-->
                <template slot-scope="scope">
                  <el-switch
                    v-model="ifDisabled[scope.$index]"
                    :disabled="ifDisabled[scope.$index]"
                    @change="changeStatus(scope.$index)"
                  />
                </template>
              </el-table-column>
              <el-table-column label="报名信息"  align="center">
                <template slot-scope="scope">
                  <el-button size="small" type="text" @click="setClassId(scope.row.cid)">查看</el-button>
                </template>
              </el-table-column>
              <el-table-column fixed="right" label="操作"  align="center">
                <template slot-scope="scope">
                  <!--                  <el-button size="small"   type="primary" @click="handleClick(scope.$index)">编辑</el-button>-->
<!--                  <el-button size="small" icon="el-icon-edit" @click="handleClick(scope.$index)" />-->
                  <el-button v-if="scope.row.classState==2" size="small" type="primary" disabled>开班</el-button>
                  <el-button v-else size="small" type="primary" @click="offerClass(scope.row.cid)">开班</el-button>
                  <!--                  <el-button size="small" type="text" @click="setClassId(scope.row.cid)">查看</el-button>-->
                </template>
              </el-table-column>
            </el-table>
            <el-pagination
              v-if="chooseOne"
              style="margin-top: 10px;float: right;margin-bottom: 10px"
              :current-page="page.pageNum"
              :total="page.totalSize"
              layout="total,prev, pager, next, jumper"
              @current-change="handleCurrentChange"
            />
            <!--            <el-pagination-->
            <!--              v-if="chooseOne"-->
            <!--              :current-page="pageOne.pageNumOne"-->
            <!--              :total="pageOne.totalSizeOne"-->
            <!--              @current-change="handleCurrentChange_One"-->
            <!--            />-->
            <el-table
              v-if="chooseZero"
              :data="tableDataZero"
              style="width: 100%"
              size="small"
              stripe
            >
              <el-table-column prop="className" label="班级名称" style="width: 25%">
                <template slot-scope="scope">
                  {{ scope.row.className ? scope.row.className :'暂无' }}
                </template>
              </el-table-column>
              <!--              <el-table-column v-if="chooseZero" prop="grade" label="班级年级" width="110">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                  {{ scope.row.grade===this.grades[0].value ? this.grades[0].lable :scope.row.grade===this.grades[1].value ?this.grades[1].lable :scope.row.grade===this.grades[2].value ?this.grades[2].lable:'暂无' }}&ndash;&gt;-->
              <!--                  {{ scope.row.grade?scope.row.grade:'暂无' }}-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <el-table-column prop="teacherName" label="班主任" style="width: 25%">
                <template slot-scope="scope">
                  {{ scope.row.teacherName ? scope.row.teacherName :'暂无' }}
                </template>
              </el-table-column>
              <el-table-column prop="limitOfNumber" label="人数" style="width: 25%">
                <template slot-scope="scope">
                  {{ scope.row.limitOfNumber ? scope.row.currentNumber?scope.row.currentNumber+'/'+scope.row.limitOfNumber:'0/'+scope.row.limitOfNumber :'暂无数据' }}
                </template>
              </el-table-column>
<!--              <el-table-column fixed="right" label="操作" style="width: 25%">-->
<!--                <template slot-scope="scope">-->
<!--                  &lt;!&ndash;                  <el-button type="primary" icon="el-icon-edit" @click="handleClick(scope.$index)"></el-button>&ndash;&gt;-->
<!--&lt;!&ndash;                  <el-button size="small" type="primary" icon="el-icon-edit" @click="handleClick(scope.$index)" />&ndash;&gt;-->
<!--                </template>-->
<!--              </el-table-column>-->
            </el-table>
            <el-pagination
              v-if="chooseZero"
              :current-page="pageZero.pageNumZero"
              :total="pageZero.totalSizeZero"
              style="margin-top: 10px;float: right;margin-bottom: 10px"
              layout="total,prev, pager, next, jumper"
              @current-change="handleCurrentChange_Zero"
            />
          </div>
        </el-card>
      </el-main>
    </el-container>

    <el-dialog title="填写教学班信息" :visible.sync="dialogFormVisible">
      <el-form ref="ruleForm" :inline="true" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm" style="width: 500px " label-position="left">
        <el-form-item label="班级名称" prop="className">
          <el-input v-model.trim="ruleForm.className" style="width: 390px" />
        </el-form-item>
        <!--        <el-form-item label="班级类型" prop="classType">-->
        <!--          <el-select v-model="ruleForm.classType" placeholder="请选择班级类型">-->
        <!--            <el-option v-for="item in classTypes" :key="item.value" :label="item.lable" :value="item.value" />-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->
        <el-form-item label="开班星期" prop="openingWeek">
          <el-input v-model.number="ruleForm.openingWeek" style="width: 390px" />
        </el-form-item>
        <el-form-item label="人数限制" prop="limitOfNumber">
          <el-input v-model.number="ruleForm.limitOfNumber" style="width: 390px" />
        </el-form-item>
        <el-form-item
          v-for="(it, index) in courseList"
          :key="it.courseId"
          label="* 开设课程"
        >
          <!--          <label slot="label">&nbsp;&nbsp;&nbsp;课程&nbsp;</label>-->
          <template>
            <el-select
              v-model="courseList[index].courseId"
              filterable
              remote
              value-key="courseId"
              placeholder="请选择课程"
              style="width: 155px"
              @change="saveCidList($event, index),getCidTeachers($event, index)"
            >
              <el-option
                v-for="item in courseOptions"
                :key="item.cid"
                :label="item.name"
                :value="item.cid"
              />
              <div style="bottom: 0;width: 100%;background: #fff">
                <el-pagination
                  small
                  :current-page="pageCourse.pageNumCourse"
                  :total="pageCourse.totalSizeCourse"
                  layout="prev, pager,next,total"
                  @current-change="handleCurrentChangeCourse"
                />
              </div>
            </el-select>
            -
            <el-select
              v-model="courseList[index].teacherId"
              filterable
              remote
              style="width: 155px"
              value-key="teacherId"
              placeholder="请选择任课教师"
              @change="saveTidList($event, index)"
            >
              <el-option
                v-for="item in cidToTeachersOptions"
                :key="item.tid"
                :label="item.teacherName"
                :value="item.tid"
              />
            </el-select>
          </template>

        </el-form-item>
        <el-row>
          <el-form-item label="上课时间" prop="classWeekday">
            <el-select v-model="ruleForm.classWeekday" style="width: 150px" placeholder="请选择上课时间">
              <el-option v-for="item in classWeekdayOptions" :key="item.value" :label="item.lable" :value="item.value" />
            </el-select>
          </el-form-item>
          <!--        <el-row style="padding-left: 90px">-->
          <el-form-item prop="classStartNum">
            第 <el-input v-model.number="ruleForm.classStartNum" style="width: 60px" /> 节  至
          </el-form-item>
          <el-form-item prop="classEndNum">
            第 <el-input v-model.number="ruleForm.classEndNum" style="width: 60px" /> 节
          </el-form-item>
        </el-row>
        <el-form-item style="padding-left: 100px">
          <el-button @click="dialogFormVisible = false;resetForm('ruleForm')">取 消</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
          <el-button type="primary" @click="submitForm();resetForm('ruleForm')">确 定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="填写行政班信息" :visible.sync="dialogFormVisible_administrativeClass">
      <el-form ref="ruleForm_administrativeClass" :model="ruleForm_administrativeClass" :rules="rules_administrativeClass" label-width="100px" class="demo-ruleForm" style="width: 500px " label-position="left">
        <el-form-item label="班级名称" prop="className ">
          <el-input v-model.trim="ruleForm_administrativeClass.className" />
        </el-form-item>
        <el-form-item label="年  级" prop="grade">
          <el-select v-model="ruleForm_administrativeClass.grade" placeholder="请选择年级">
            <el-option v-for="item in grades" :key="item.value" :label="item.lable" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="班主任" prop="headTeacherId">
          <el-select v-model="ruleForm_administrativeClass.headTeacherId" placeholder="请选择班主任">
            <el-option v-for="item in teacherOptions" :key="item.tid" :label="item.teacherName" :value="item.tid" />
          </el-select>
        </el-form-item>
        <el-form-item label="人数限制" prop="limitOfNumber">
          <el-input v-model.number="ruleForm_administrativeClass.limitOfNumber" />
        </el-form-item>
        <el-form-item>
          <el-button
            @click="dialogFormVisible_administrativeClass = false;resetForm_administrativeClass('ruleForm_administrativeClass')"
          >取 消</el-button>
          <el-button type="primary" @click="submitForm_administrativeClass();dialogFormVisible_administrativeClass = false;resetForm_administrativeClass('ruleForm_administrativeClass')">确 定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog title="报名信息" :visible.sync="dialogTableVisible">
      <el-table :data="enrollList">
        <el-table-column prop="oid" label="订单号" width="220" />
        <el-table-column label="是否支付" width="100">
          <template slot-scope="s">
            {{ s.row.state==0?"否":"是" }}
          </template>
        </el-table-column>
        <el-table-column prop="subscribe" label="描述" />
        <el-table-column label="操作" width="270">
          <template slot-scope="s">
            <el-button type="primary" @click="getOrderDetail(s.row.oid)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :hide-on-single-page="true"
        :page-size="orderPage.pageSize"
        :current-page="orderPage.pageNum"
        :total="orderPage.totalSize"
        @current-change="handleTableCurrentChange"
      />
    </el-dialog>

    <el-dialog title="订单详情" :visible.sync="dialogOrderDetailVisible" width="20%">
      <el-form ref="orderDetail" :model="orderDetail" label-width="100px">
        <el-form-item label="学生姓名">{{ orderDetail.childName ? orderDetail.childName : "无" }}</el-form-item>
        <el-form-item label="性别">{{ orderDetail.gender ? orderDetail.gender : "无" }}</el-form-item>
        <el-form-item label="家长">{{ orderDetail.parentName ? orderDetail.parentName : "无" }}</el-form-item>
        <el-form-item label="家长电话">{{ orderDetail.parentPhoneNumber ? orderDetail.parentPhoneNumber : "无" }}</el-form-item>
        <el-form-item label="订单创建时间">{{ orderDetail.createTime ? orderDetail.createTime : "无" }}</el-form-item>
        <el-form-item label="总费用">{{ orderDetail.totalAmount ? orderDetail.totalAmount + '元' : "无" }}</el-form-item>
      </el-form>
    </el-dialog>
  </div>

</template>
<script>
import { changeClassState, preinstallInfo } from '../../../api/class'
import { getTeacherInfo, getTeacherList } from '../../../api/teacher'
import { getAllCourse } from '../../../api/course'
import { getClass } from '../../../api/class'
import { checkEnrollInfo, getOrderByOid } from '../../../api/order'
import { getStudentList } from '../../../api/student'
import { getCidToTeachers } from '../../../api/teacher'

export default {
  name: 'Preinstall',
  data() {
    return {
      showSecondButton:false,
      showFirstButton:true,
      activeIndex: '1',
      valueSignUp: [],
      List: [],
      chooseAll: false,
      chooseZero: false, // 行政班
      chooseOne: true, // 教学班
      searchType: [
        {
          id: '1',
          name: '教学班'
        },
        {
          id: '0',
          name: '行政班'
        }
      ],
      Type: '1',
      yearNow: '',
      ifDisabled: [],
      state: '',
      flagT: false,
      flagC: false,
      isHeadTeacher: '',
      cidToTeachersOptions: [],
      props: { multiple: true },
      grades: [],
      classWeekdayOptions: [
        {
          value: 1,
          lable: '周一'
        },
        {
          value: 2,
          lable: '周二'
        },
        {
          value: 3,
          lable: '周三'
        },
        {
          value: 4,
          lable: '周四'
        },
        {
          value: 5,
          lable: '周五'
        },
        {
          value: 6,
          lable: '周六'
        },
        {
          value: 7,
          lable: '周日'
        }
      ],
      page: { // 教学班
        pageNum: 1,
        pageSize: 10,
        totalPage: 0,
        totalSize: 0
      },
      pageZero: { // 行政班
        pageNumZero: 1,
        pageSizeZero: 10,
        totalPageZero: 0,
        totalSizeZero: 0
      },
      // pageOne: { // 教学班
      //   pageNumOne: 1,
      //   pageSizeOne: 10,
      //   totalPageOne: 0,
      //   totalSizeOne: 0
      // },
      pageCourse: {
        pageNumCourse: 1,
        pageSizeCourse: 10,
        totalPageCourse: 0,
        totalSizeCourse: 0
      },
      tableData: [],
      tableDataZero: [],
      cid: '',
      classState: '',
      dialogFormVisible_administrativeClass: false,
      dialogFormVisible: false,
      dialogTableVisible: false,
      dialogOrderDetailVisible: false,
      ruleForm: {
        className: '',
        // classType: '',
        courseList: [],
        // headTeacherId: '',
        limitOfNumber: '',
        openingWeek: '',
        classWeekday: '',
        classStartNum: '',
        classEndNum: ''
      },
      ruleForm_administrativeClass: {
        className: '',
        headTeacherId: '',
        grade: '',
        limitOfNumber: ''
      },
      formLabelWidth: '120px',
      rules: {
        className: [
          { required: true, message: '请输入班级名称', trigger: 'blur' }
        ],
        courseList: [
          { required: true, message: '请添加课程', trigger: 'blur' }
        ],
        openingWeek: [
          { required: true, message: '请输入开班星期', trigger: 'blur' },
          { type: 'number', message: '请输入数字', trigger: 'blur' }
        ],
        limitOfNumber: [
          { required: true, message: '请输入人数限制', trigger: 'blur' },
          { type: 'number', message: '请输入数字', trigger: 'blur' }
        ],
        classStartNum: [
          { required: true, message: '请输入开始节次', trigger: 'blur' },
          { type: 'number', message: '请输入数字', trigger: 'blur' }
        ],
        classEndNum: [
          { required: true, message: '请输入结束节次', trigger: 'blur' },
          { type: 'number', message: '请输入数字', trigger: 'blur' }
        ],
        classWeekday: [
          { required: true, message: '请选择上课时间', trigger: 'blur' }
        ]
      },
      rules_administrativeClass: {
        className: [
          { required: true, message: '请输入行政班名称', trigger: 'blur' }
        ],
        limitOfNumber: [
          { required: true, message: '请输入人数限制', trigger: 'blur' },
          { type: 'number', message: '请输入数字', trigger: 'blur' }
        ],
        grade: [
          { required: true, message: '请选择年级', trigger: 'blur' }
        ],
        headTeacherId: [
          { required: true, message: '请选择班主任', trigger: 'blur' }
        ]
      },
      class: {
        baseCost: '',
        cid: '',
        className: '',
        classState: '0',
        classType: '',
        currentNumber: '0',
        dinnerCost: '',
        headTeacherId: '',
        limitOfNumber: '',
        materialCost: '',
        openingWeek: ''
      },
      teacherOptions: [],
      courseOptions: [],
      courseList: [
        {
          courseId: '',
          teacherId: ''
        }
      ],
      course: [
        {
          id: ''
        }
      ],
      list: [
        {
          courseId: '',
          teacherId: ''
        }
      ],
      enrollList: [],
      orderParam: {
        classId: '',
        pageSize: '10',
        pageNum: '1'
      },
      orderPage: {},
      orderDetail: {}
    }
  },
  created() {
    this.getAllHeadTeacherList()
    this.getAllCourseList()
    this.getAllClassOne()
    this.getTime()
  },
  methods: {
    handleSelect(key, keyPath) {
      if (key === '1') {
        this.chooseZero = false
        this.chooseAll = false
        this.chooseOne = true
        this.showSecondButton=false
        this.showFirstButton=true
        this.getAllClassOne()
      } else if (key === '2') {
        this.chooseOne = false
        this.chooseAll = false
        this.chooseZero = true
        this.showFirstButton=false
        this.showSecondButton=true
        this.getAllClassZero()
      }
    },
    getTime() {
      const date = new Date()
      this.yearNow = date.getFullYear()
      console.log(this.yearNow)
      this.grades.push({
        value: this.yearNow,
        lable: this.yearNow + '级小班' })
      this.grades.push({
        value: this.yearNow - 1,
        lable: this.yearNow - 1 + '级中班'
      })
      this.grades.push({
        value: this.yearNow - 2,
        lable: this.yearNow - 2 + '级大班'
      })
    },
    handleCurrentChange_Zero(val) {
      this.pageZero.pageNumZero = val
      this.getAllClassZero()
    },
    handleCurrentChange(val) {
      this.page.pageNum = val
      this.getAllClassOne()
    },
    // handleCurrentChange_One(val) {
    //   this.pageOne.pageNumOne = val
    //   this.getAllClassOne()
    // },
    handleCurrentChangeCourse(val) {
      this.pageCourse.pageNumCourse = val
      this.getAllCourseList()
    },
    // getClassSearch() {
    //   if (this.Type === '1') {
    //     // 获取教学班
    //     this.chooseZero = false
    //     this.chooseAll = false
    //     this.chooseOne = true
    //     this.getAllClassOne()
    //   } else if (this.Type === '0') {
    //     // 获取行政班
    //     this.chooseOne = false
    //     this.chooseAll = false
    //     this.chooseZero = true
    //     this.getAllClassZero()
    //   }
    // },
    getAllClassZero() {
      getClass({
        classType: 0,
        pageNum: this.pageZero.pageNumZero,
        pageSize: this.pageZero.pageSizeZero
      }).then(async res => {
        this.List = res.data.list
        this.pageZero.pageSizeZero = res.data.page.pageSize
        this.pageZero.pageNumZero = res.data.page.pageNum
        this.pageZero.totalSizeZero = res.data.page.totalSize
        this.pageZero.totalPageZero = res.data.page.totalPage
        this.ifDisabled = []
        for (var i = 0; i < this.tableDataZero.length; i++) {
          if (this.tableDataZero[i].classState === 1) {
            this.ifDisabled[i] = true
          } else {
            this.ifDisabled[i] = false
          }
        }
        this.Type = '0'
        this.chooseOne = false
        this.chooseZero = true
        // 根据班级id获取该班班主任
        for (var i = 0; i < res.data.list.length; i++) {
          var id = this.List[i].headTeacherId
          await getTeacherInfo(id)
            .then(res => {
              this.teacher_Name = res.data.teacherName
              this.List[i].teacherName = this.teacher_Name
              // this.$message.success('请求班主任成功！')
            })
            // .catch(err => {
            //   this.$message.error('请求班主任失败！')
            // })
        }
        this.tableDataZero = this.List
        // this.$message.success('请求行政班列表成功')
      })
      // .catch(err => {
      //   this.$message.error('请求行政班列表失败！')
      // })
    },
    getAllClassOne() {
      getClass({
        classType: 1,
        pageNum: this.page.pageNum,
        pageSize: this.page.pageSize
        // pageNum: this.pageOne.pageNumOne,
        // pageSize: this.pageOne.pageSizeOne
      }).then(res => {
        this.tableData = res.data.list
        this.page = res.data.page
        // this.pageOne.pageNumOne = res.data.page.pageNum
        // this.pageOne.pageSizeOne = res.data.page.pageSize
        // this.pageOne.totalPageOne = res.data.page.totalPage
        // this.pageOne.totalSizeOne = res.data.page.totalSize
        this.ifDisabled = []
        for (var i = 0; i < this.tableData.length; i++) {
          if (this.tableData[i].classState === 1 || this.tableData[i].classState === 2) {
            this.ifDisabled[i] = true
            console.log(i)
          } else {
            console.log('!!!')
            this.ifDisabled[i] = false
          }
        }
        this.Type = '1'
        this.chooseOne = true
        this.chooseZero = false
        // this.$message.success('请求教学班级列表成功')
      })
      // .catch(err => {
      //   this.$message.error('请求教学班级列表失败！')
      // })
    },
    saveCidList(event, index) {
      this.courseList[index].courseId = event
      this.course[index].id = event
      this.list[index].courseId = event
      this.flagC = true
    },
    saveTidList(event, index) {
      this.courseList[index].teacherId = event
      this.list[index].teacherId = event
      this.flagT = true
    },
    submitForm() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          // alert('预设成功!')
          if (this.flagC === false && this.flagT === false) {
            alert('请选择课程及教师!')
          } else {
            this.dialogFormVisible = false
            this.preinstallClassInfo()
          }
        } else {
          alert('填写不符合要求')
          return false
        }
      })
    },
    submitForm_administrativeClass() {
      // 创建行政班，提交表单
      this.$refs.ruleForm_administrativeClass.validate((valid) => {
        if (valid) {
          preinstallInfo({
            className: this.ruleForm_administrativeClass.className,
            limitOfNumber: this.ruleForm_administrativeClass.limitOfNumber,
            classType: 0,
            grade: this.ruleForm_administrativeClass.grade,
            headTeacherId: this.ruleForm_administrativeClass.headTeacherId
          }).then(res => {
            this.$message.success('行政班预设成功！')
            this.getAllClassZero()
          })
          // .catch(err => {
          //   this.$message.error('行政班预设失败！')
          // })
        } else {
          alert('填写不符合要求')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.courseList = [
        {
          courseId: '',
          teacherId: ''
        }
      ]
    },
    resetForm_administrativeClass(formName) {
      // 重置创建行政班表单
      this.$refs[formName].resetFields()
    },
    preinstallClassInfo() {
      preinstallInfo({
        className: this.ruleForm.className,
        openingWeek: this.ruleForm.openingWeek,
        limitOfNumber: this.ruleForm.limitOfNumber,
        classType: 1,
        course: this.list,
        classWeekday: this.ruleForm.classWeekday,
        classStartNum: this.ruleForm.classStartNum,
        classEndNum: this.ruleForm.classEndNum
      }).then(res => {
        this.$message.success('预设班级成功！')
        this.getAllClassOne()
      })
      // .catch(err => {
      //   this.$message.error('预设班级请求失败！')
      // })
    },
    getAllHeadTeacherList() {
      getTeacherList(
        {
          isHeadTeacher: 2,
          pageNum: this.page.pageNum,
          pageSize: this.page.pageSize
        }
      ).then(res => { this.teacherOptions = res.data.list })
      // .catch(err => {
      //   this.$message.error('请求教师列表失败！')
      // })
    },
    getAllCourseList() {
      getAllCourse(
        {
          state: 1,
          pageNum: this.pageCourse.pageNumCourse,
          pageSize: this.pageCourse.pageSizeCourse
        }
      ).then(res => {
        this.courseOptions = res.data.list
        this.pageCourse.pageNumCourse = res.data.page.pageNum
        this.pageCourse.pageSizeCourse = res.data.page.pageSize
        this.pageCourse.totalPageCourse = res.data.page.totalPage
        this.pageCourse.totalSizeCourse = res.data.page.totalSize
      })
      // .catch(err => {
      //   this.$message.error('请求课程列表失败！')
      // })
    },
    getCidTeachers(event, index) {
      this.cidToTeachersOptions = []
      this.courseList[index].teacherId = ''
      getCidToTeachers(this.courseList[index].courseId)
        .then(res => {
          this.cidToTeachersOptions = res.data
          if (this.cidToTeachersOptions.length === 0) {
            this.courseList[index].teacherId = '暂无可担任教师'
          }
        })
      // eslint-disable-next-line handle-callback-err
      //   .catch(err => {
      //     this.$message.error('请求该课程可担任教师列表失败！')
      //   })
    },
    // 开班功能
    offerClass(cids) {
      this.cid = cids
      this.$confirm('是否确认开班?', '开班提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        changeClassState({
          cid: this.cid,
          classState: '2'
        }).then(res => {
          this.$message.success('请求成功！')
          this.$message({
            type: 'success',
            message: '成功开班'
          })
        })
          .catch(err => {
            console.log('cid', this.cid)
            this.$message.error('请求失败！')
          })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消操作'
        })
      })
    },
    // 设置classId
    setClassId(cid) {
      this.enrollList = null
      console.log('cid', cid)
      this.orderParam.classId = cid
      console.log('cid', this.orderParam.classId)
      this.checkEnroll()
    },
    // 查看报名信息
    checkEnroll() {
      checkEnrollInfo({
        classId: this.orderParam.classId,
        pageNum: this.orderParam.pageNum,
        pageSize: this.orderParam.pageSize
      }).then(res => {
        this.enrollList = res.data.list
        this.orderPage = res.data.page
        this.dialogTableVisible = true
        console.log('page', res.data.page)
        // eslint-disable-next-line handle-callback-err
      }).catch(err => {
        console.log('err', err)
        this.$message.error('请求报名信息失败！')
      })
    },
    // 获取订单详情
    getOrderDetail(oid) {
      let sid = ''
      getOrderByOid(
        oid
      ).then(res => {
        this.orderDetail.totalAmount = res.data.totalAmount
        this.orderDetail.createTime = res.data.createTime
        sid = res.data.sid
        getStudentList({
          sid: sid
        }).then(res => {
          this.orderDetail.childName = res.data.list[0].childName
          this.orderDetail.parentName = res.data.list[0].parentName
          this.orderDetail.parentPhoneNumber = res.data.list[0].parentPhoneNumber
          this.orderDetail.gender = res.data.list[0].gender
          this.dialogOrderDetailVisible = true
        }).catch(err => {
          console.log('err', err)
          this.$message.error('请求学生失败！')
        })
      }).catch(err => {
        console.log('err', err)
        this.$message.error('请求报名信息详情失败！')
      })
    },
    // 订单翻页
    handleTableCurrentChange(val) {
      this.orderParam.pageNum = val
      this.checkEnroll()
    },
    changeStatus(index) {
      if (this.tableData[index].classState === 1) {
        alert('该班级已开启报名，无需重复开启')
      } else if (this.tableData[index].classState === 2) {
        alert('该班级已开班，不能开启报名')
      } else if (this.tableData[index].classState === 3) {
        alert('改班级已废弃，不能开启报名')
      } else {
        changeClassState({
          cid: this.tableData[index].cid,
          classState: 1
        }).then(res => {
          this.$message.success('开启报名成功！')
          this.getAllClassOne()
        })
        // .catch(err => {
        //   this.$message.error('开启报名失败！')
        // })
      }
    }
  }
}
</script>

<style scoped>
  .el-header{
    line-height:80px;
    margin-left: 10px;
  }
  .text{
    font-size: 20px;
    font-weight: bold;
  }

</style>
